<extend name="common:commonSimpleNewTemplate" />
<block name="main_content">
<style type="text/css">
.table th{
	border-top :1px solid #ddd;
    border-bottom: 1px solid #ddd;
}
.table td {
	border-top :0px;
    border-bottom: 1px solid #ddd;
}
.line-before{
    border-bottom: 0px solid #eeeeee!important;
    border-top: 0px solid #ffffff!important;
    margin-left: 0 !important;
}
.line-after [class*="control-label"]{
	padding-right: 20px!important;
}
</style>


<div class="row-fluid" id="biz_dealer" >
	<div class="span12">
		<div class="widget-box" style="margin-bottom: 0;margin-top: 10px;">
				<div class="widget-content nopadding">
					<form novalidate="novalidate" id="basic_validate" name="basic_validate" action="#" method="post" class="form-horizontal">
						
						<div class="control-group span6 line-before">
						<!-- 	<label class="control-label">产品编号:</label>
							<div class="controls">
								<input t>
								<input type="text" id="s_product_id" name="s_product_id" value="{$s_product_id}"/>
							</div> -->
							
						   <label class="control-label">产品类型<span class="required-tips">*</span></label>
                           <div class="controls">
                              <select id="s_product_type" name="s_product_type"  style="width: 77%">
                              	<option value="" selected="selected">全部</option>
                            	<foreach  name="product_type_lst" item="display" key="code">
									<option value="{$code}">{$display}</option>
								</foreach >
                              </select>
                           </div>
						</div>
						<div class="control-group line-after">
							<label class="control-label">产品名称:</label>
							<div class="controls">
								<input type="text" id="s_product_nme" name="s_product_nme" value="{$s_product_nme}"/>
							</div>
						</div>
						<div class="control-group span6 line-before">
							<label class="control-label">客户物料号:</label>
							<div class="controls">
								<input type="text" id="s_material_no" name="s_material_no" value="{$s_material_no}"/>
							</div>
						</div>
						<div class="control-group line-after">
							<label class="control-label">客户物料号描述:</label>
							<div class="controls">
								<input type="text" id="s_material_desc" name="s_material_desc" value="{$s_material_desc}"/>
							</div>
						</div>
						<div class="form-actions">
							<input id="btn_product_query" type="button" class="btn btn-success" value="搜索">
							<input id="btn_product_reset" type="button" class="btn btn-danger" value="重置">
						</div>
					</form>
				</div>
  				 <div class="widget-content nopadding" style="height:351px;overflow: auto;">
    					 <table id="search_result" page_index="1" class="table table-bordered table-striped">
				 	 	 	 <thead>
		      					<tr>
		      					  <th width="20px" >选择</th>
		      					  <th>产品编号</th>
		       					  <th>产品名称</th>
		       					  <th>产品类型</th>
	        					  <th>客户物料号</th>
	        					  <th>客户物料号描述</th>
	                          </tr>
	                         </thead>
	                         <tbody>
		            			<!-- <if condition="empty($lst_product_info)">
									<tr><td colspan="5" style="text-align: center;">暂时没有数据</td></tr>
									<else /> 
									<volist name="lst_product_info" id="product_info" empty="暂时没有数据">
									<tr>
									    <td width="20px"> <input class='input_check_box' name='checkOneBox' product_id='{$product_info.product_id}' type='radio' style='position:relative;width: 50px; opacity: 100;'></td>
										<td>{$product_info.product_id}</td>
										<td>{$product_info.product_name}</td>
										<td>{$product_info.material_no}</td>
										<td>{$product_info.material_desc}</td>
									</tr>
									</volist> 
								</if> -->
	                         </tbody>
                     	</table>
             	</div>
					<div class="row-fluid nopadding" id="controller_div" style="height: 30px">
	           			<if condition="!empty($lst_product_info)">
								<button id='check_this_product' style="margin: 0px 0px 0px -1px" class="btn btn-danger" type="submit">确认产品</button>
							<else /> 
								&nbsp;
						</if>
					</div>
		</div>
	</div>
</div>
</block>

<block name="js_content">
<script src="/Public/js/layer/layer.js" type="text/javascript"></script>
<script>

ProductSearchPage = {
		'BindEvent': function(){
			$('#check_this_product').bind('click',ProductSearchPage.LoadProduct);
			$('#btn_product_query').bind('click',ProductSearchPage.SearchProduct);
			$('#btn_product_reset').bind('click',ProductSearchPage.Reset);
		},
		'Reset':function(){
			$('#s_product_type').val('');
			$('#s_product_nme').val('');
			$('#s_material_no').val('');
			$('#s_material_desc').val('');
		},
		'LoadProduct':function(){
			var product_id = '';
			$('input[name="checkOneBox"]:checked').each(function(){ 
				product_id = $(this).attr('id'); 
			}); 
			if(product_id ==''){
				layer.msg('请选择一个产品!', {icon: 5});
				return;
			}
			var condition = 'product_id=' + product_id;
            $.ajax({
                type: 'post',
                url: '/AjaxService/center/sku/queryProductById',
                data: condition,
                dataType: 'json',
                success: function (data) {
                	parent.SkuPageInfo.BuildPage(data);
        			var index = parent.layer.getFrameIndex(window.name); //获取当前窗体索引
        		    parent.layer.close(index); //执行关闭
                },
                error: function (e, err_name, err_text) {
                    alert(err_text);
                }
            });
		} , 
		'SearchProduct':function(){
			var params = {};
            params.product_type = $('#s_product_type').val();
            params.product_name = $('#s_product_nme').val();
            params.material_no = $('#s_material_no').val();
            params.material_desc = $('#s_material_desc').val();

            $.ajax({
                type: 'post',
                url: '/AjaxService/center/sku/queryProductInfo',
                data: params,
                dataType: 'json',
                success: function (data) {
                	ProductSearchPage.BindTable(data.Result);
                },
                error: function (e, err_name, err_text) {
                    alert(err_text);
                }
            });
		},
		'BindTable': function(lst_product){
			if(lst_product.length == 0){	
				$('#search_result tbody').html('');
				var msg ="<tr><td colspan='6' style='text-align:center'>暂时没有数据!</td></tr>";				
				$('#search_result tbody').append(msg);	
			}else{
				var html = '';
				for(var index in lst_product){
					var product_en = lst_product[index];
					var tr_html = "<tr>";
					tr_html += "<td width='20px' ><input name='checkOneBox' id='" + product_en.product_id +"'   type='radio' ></td>";
					tr_html += "<td>" + ProductSearchPage.convertNull(product_en.product_id) + "</td>";
					tr_html += "<td>" + ProductSearchPage.convertNull(product_en.product_name) + "</td>";
					tr_html += "<td>" + ProductSearchPage.ConvertOptions('product_type_options',product_en.product_type) + "</td>";
					tr_html += "<td>" + ProductSearchPage.convertNull(product_en.material_no) + "</td>";
					tr_html += "<td>" + ProductSearchPage.convertNull(product_en.material_desc) + "</td>";
					tr_html += "</tr>";
					html += tr_html;
				} 
				$('#search_result tbody').html('');
				$('#search_result tbody').append(html);
				ProductSearchPage.whaleyUniform();
			}
		},
		'whaleyUniform' : function(){
			 $('input[type=radio]').uniform();
			 $('.radio span').bind('click',function(){
				 var obj = $(this).find("input[type=radio]");
				 $(obj).prop('checked',true);
				 $.uniform.update();
			});
			 /* $('.input_check_box').bind('click',function(){
				$('.input_check_box').removeAttr('checked');
				$(this).attr("checked", true);
			});  */
		},
		'convertNull' : function (str) { //共通转空操作
	        if (str) return str;
	        return "";
	 	},
	 	'ConvertOptions': function(type,obj){
			var display = '【转换失败:'+obj+'】';
			$.each(ProductSearchPage[type], function(key, value){
			  if(key == obj){
				  display = value;
				  return false;
			  }
			});
			return display;
		}
};


$(document).ready(function(){
	ProductSearchPage.product_type_options = eval({$product_type_options});
	var data = eval({$lst_product_info})
	ProductSearchPage.BindTable(data);
	ProductSearchPage.BindEvent();
});

</script>
</block>